package com.lq.learningTest.duoxiancheng;

public class Lock {
//    public synchronized void say(){
//        try {
//            Thread.sleep(100);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
//        System.out.println("hello");
//        System.out.println("-------"+Math.random()+"--------");
//    }
    private static Lock lock = new Lock();
    public void say(){
        synchronized(this){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("hello");
            System.out.println("-------"+Math.random()+"--------");
        }

    }

    public static synchronized void say2(){
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("hello2-------");
        System.out.println("-------"+Math.random()+"--------");
    }
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                lock.say();
            }).start();
        }
    }
}
